#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "iodev.h"
#include "network.h"
#include "reason.h"
#include "systemfile.h"
#include "ticketdevfile.h"
#include "udpsocket.h"
#include <QTimer>
#include <QPaintEvent>
#include <QDateTime>
#include <QDate>
#include <camera.h>
#include <pthread.h>
#include <QFtp>
#include "scrollarea.h"
#include "mysqllink.h"
#include "filemanage.h"
#include "scandev.h"
#include "uart.h"
#include "car_product.h"
#include "put_image.h"
#include "mywatch.h"
#include <QPixmap>
#include <QtWebKit/QtWebKit>
#include <QtWebKit/QWebView>
#include"ledtcp.h"
#include "MyKeyboard.h"
#include "dateset.h"

#define CAMERA_OFF_TIMER   3000   //最大空闲时间
enum HandStatus{HandReason=1,HandSend=2};
enum STATUS{CARIN=1,CAROUT=2};
enum DIRSTATUS{DIRLOCAL=1,DIRTEMP=2};
namespace Ui {
class MainWindow;
}

class Carployee
{
public:
    Carployee(): carFlag() {}
    Carployee( const QString &carName, const QDateTime&surTime)
        : carFlag(carName), carTime(surTime)
    {}
    QString carName() const { return carFlag; }
    QDateTime surTime() const { return carTime; }
private:
    QString carFlag;
    QDateTime carTime;
};

class MainWindow : public QMainWindow
{
    Q_OBJECT
    
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    bool eventFilter(QObject *obj, QEvent *event);
    void closeEvent( QCloseEvent * event );
    //QMap<QString,QDateTime> car_map; //定义一个QMap对象
    typedef QMap <QString,Carployee> CarParkMap; //自定义一个map类型，值为EmployeeMap对象
    CarParkMap car_map;
    void showTime();
    void bzeroInfo(displayData_t &info);
    void makeAudio(displayData_t &info);
private:
    Ui::MainWindow *ui;
    //QPixmap screen;
    //QPixmap screen2;
    //QPixmap screen3;
    //QPixmap screen4;
    ctrl_type dataBuf;
    //Reason *reason_in;
    MyWatch *watch_dog;
    HandStatus handinfor;
    int ok;
    int fdCom1,fdCom2,fdCom4;
    QSocketNotifier *notifierCom1,*notifierCom2,*notifierCom3,*notifierCom4;
    scanDev *scanInDev,*scanOutDev;

    camera *cameraIn,*cameraOut;
    ledTcp *udpLed;
    network *my_network;
    Car_Product *down_network;
    //  Producer *pud[20];

    QTimer *timer,*timer_receive,*timer2_receive,*timer_update,*timer_down,*timer_in,*timer_out,*timer_carIn,*timer_carOut,*timer_update2/*新增定时器，用于还原出口显示屏信息*/;
    QTimer *timer_CarDown,*time_putimage,*timer_dataBaseLink,*timer_map,*timer_dog,*timer_dispalay,*timer_recordDown,*timer_recordup,*timer_bind_down,*timer_stall_down;
    QTimer *timer_quit_carNumberIn,*timer_quit_carNumberOut;
    datebase *myDb;
    udpSocket *udpLink;
    scrollarea *scroll;
    QPixmap inPixmap,outPixmap;
    QTextCodec *gb2312;
    QTextCodec *utf8;
    MysqlLink *mysql_link;
    Put_Image *Image_link;
    int heart;
    //QString InforCar_id;
    FileManage *filelink;
    QDateTime LinkInTime,LinkOutTime,TurnClassTime;
    QString Camera_picIn,Camera_picOut;
    int picput_flag;//0不上传，1上传
    ticketCheck_t Car_OutInfor;
    QByteArray ic_cardno;
    bool time_flag,serIP_flag;
    QString Car_InVehicle,Car_OutVehicle;
    QString ser_IP1,ser_IP2;
    //QPixmap screen;

    QString pic_name;
    QString day_flag;
    QString hand_carIn;

    QString camera_inpic,camera_outpic,IcCardNum;
    QString CarInPicName,CarOutError;
    QString CAR_SEAT;
    int park_type_flag;
    int park_fee_flag;
    int passwd_flag;
    bool carNumberIn_flag,carNumberOut_flag;
    Widget w;
    QString park_form_flag;
    int pass_flag_heart;
private slots:
    void carNumberIn_Slot(QString carNum,QPixmap *pic);
    void carNumberOut_Slot(QString carNum,QPixmap *pic);
    void initialization();

    void initntp();
    void initComDevice();
    void initWeb();
    void initFtp();
    void initUdp();
    void initPaint();
    void initTimer();
    void initCamera();
    void initFile();
    void initMysdate();

    void udpRecProcess();
    void carupdate_send();
    void put_recordInOut();
    void put_image();
    void put_firstcar();
    void down_car();

    void reason_show();
    void camera_in();
    void camera_out();

    void CarInfinishedSlot(QNetworkReply *reply);
    void CarOutfinishedSlot2(QNetworkReply *reply);
    void TimefinishedSlot(QNetworkReply *reply);
    void RemainfinishedSlot(QNetworkReply *reply);
    void ReasonfinishedSlot(QNetworkReply *reply);
    void HandfinishedSlot3(QNetworkReply *reply);
    void CarfinishedSlot4(QNetworkReply *reply);
    void InOutfinishedSlot5(QNetworkReply *reply);
    void InOutfinishedSlot6(QNetworkReply*);
    void CarFirstSlot(QNetworkReply *reply);
    void TempImagesSlot(QNetworkReply *reply);
    void carbindfinishedSlot(QNetworkReply*);
    void carstallfinishedSlot(QNetworkReply*);

    void dispUpdata();
    void dispUpdata2(); //新增槽函数用于还原显示时间日期 停车场空位
    void disPaint();
    void on_pushButton_open_in_clicked();
    void on_pushButton_open_out_clicked();
    void on_pushButton_carIn_clicked();
    void on_pushButton_carOut_clicked();
    void on_pushButton_in_zoom_clicked();
    void on_pushButton_out_zoom_clicked();

    void paintEvent(QPaintEvent *);
    void keyPressEvent(QKeyEvent *e);
    QString Date_cureent(QString E_Date);
    void ftp_put_pic(int flag,QString map);
    void dataBaseLink();

    void write_back_in(QDateTime);
    void write_back_out(QDateTime);
    void CameraInRecive();
    void CameraOutRecive();
    void com1RecProcess();
    void com2RecProcess();
    void icRecProcess(QString);
    void CarDownProcess(QString);
    void PutImageProcess(bool mes);
    void map_carLink();

    void car_inClear();
    void car_outClear();
    int showMap(QString car_no,QString carFlag);

    void nextPageHis();
    void prePageHis();
    void on_pushButton_up_clicked();
    void on_pushButton_down_clicked();
    void on_pushButton_turnquit_clicked();

    void on_pushButton_turnok_clicked();
  //void car_inout_show(QDateTime);
    void car_inout_show(QDateTime,QDateTime,QSqlDatabase *db,int);
    void car_vehicle(QDateTime endtime,QSqlDatabase *db,int);
    void INcar_vehicle(QSqlDatabase *db,QString car_no);
    void on_pushButton_allday_clicked();

    void Car_downLink();
    void info_upLink();
    void car_stall_downLink();
    void seatbind_downLink();
    void info_downLink();
    void Image_putLink();
    void receive_cuTime(QTime);
  /*  void on_tool_0Btn_clicked();
    void on_tool_1Btn_clicked();
    void on_tool_2Btn_clicked();
    void on_tool_3Btn_clicked();
    void on_tool_4Btn_clicked();
    void on_tool_5Btn_clicked();
    void on_tool_6Btn_clicked();
    void on_tool_7Btn_clicked();
    void on_tool_8Btn_clicked();
    void on_tool_9Btn_clicked();
    void on_tool_tBtn_clicked();
    void on_tool_xBtn_clicked();*/
    void on_tool_okBtn_clicked();
    void on_tool_dBtn_clicked();
    void on_pushButton_OK_clicked();
    void Money_Auto(QString,QString num);

    void on_tableWidget_2_clicked(const QModelIndex &index);
    void on_pushButton_wiget2_back_clicked();
    void on_pushButton_wiget2_select_clicked();
    void on_pushButton_wiget2_3_clicked();
    void on_pushButton_wiget2_5_clicked();
    void on_pushButton_wiget2_up_clicked();
    void on_pushButton_wiget2_down_clicked();
    void on_tool_xBtn_clicked();

    void on_tool_0Btn_clicked();
    void on_tool_1Btn_clicked();
    void on_tool_2Btn_clicked();
    void on_tool_3Btn_clicked();
    void on_tool_4Btn_clicked();
    void on_tool_5Btn_clicked();
    void on_tool_6Btn_clicked();
    void on_tool_7Btn_clicked();
    void on_tool_8Btn_clicked();
    void on_tool_9Btn_clicked();
    void on_tool_tBtn_clicked();

    void on_pushButton_time_clicked();
    void on_pushButton_wiget2_2_clicked();
    void on_pushButton_wiget2_4_clicked();
    void on_pushButton_wiget2_6_clicked();
    void on_pushButton_widget2_ok_clicked();

    void Turn_Class();
    void In_CarRecord();
    void on_pushButton_allTime_clicked();

    void read_ini();
    void DogLink();
    bool win_read_ini();
    void imagedir_remove();
    void on_pushButton_inpic_clicked();
    QString FindCarIN(QString carNo);
    void serIP_change();

    void onHeaderClicked(int column);
    void Widget2Clicked(int column);

    void park_type_set(int);
    void park_model_set(int flag);
    void park_parktype_set(int flag);
    void park_pass_set(int flag);
    void park_tempcarin_set(int flag);
    void park_vehicle_set(int flag);
    void park_savepic_set(int flag);
    void park_firstdown_set(int flag);
    void park_fee_set(int flag);
    void park_passwd(int flag);
    void park_camera_set(int flag);
    void input_fee(int flat);
    void passwd_input_fee(int flat);
    void park_form_set(QString flag);

    void on_toolButton_AllCar_clicked();
    void on_toolButton_GuCar_clicked();
    void on_toolButton_LinCar_clicked();
    void on_toolButton_TeCar_clicked();
    void on_pushButton_set_clicked();
    void on_toolbtn_quit_clicked();
    void on_toolbtn_1_clicked();
    void on_toolbtn_2_clicked();
    void on_toolbtn_3_clicked();
    void on_toolbtn_4_clicked();
    void on_toolbtn_5_clicked();
    void on_toolbtn_6_clicked();
    void on_toolbtn_7_clicked();
    void on_toolbtn_8_clicked();
    void on_toolbtn_9_clicked();
    void on_toolbtn_0_clicked();
    void on_toolbtn_clear_clicked();

    void stackpage();
    void on_pushButton_setting_up_clicked();

    void on_pushButton_setting_down_clicked();

    void on_toolButton_fee_half_clicked();

    void on_toolButton_fee_one_clicked();

    void on_toolButton_fee_tall_clicked();

    void on_toolButton_fee0_clicked();

    void on_toolButton_fee1_clicked();

    void on_toolButton_fee2_clicked();

    void on_toolButton_fee3_clicked();

    void on_toolButton_fee4_clicked();

    void on_toolButton_fee5_clicked();

    void on_toolButton_fee6_clicked();

    void on_toolButton_fee7_clicked();

    void on_toolButton_fee8_clicked();

    void on_toolButton_fee9_clicked();

    void on_toolButton_fee10_clicked();

    void on_toolButton_fee_clear_clicked();

    void on_toolButton_passwd_clicked();

    void on_toolButton_passwdChangge_clicked();

    void on_tool_Btn_pass_ok_clicked();

    void on_tool_Btn_back_clicked();

    void on_tool_tui_clicked();

    void on_tool_clear_clicked();


    void on_tool_Btn_pass2_clicked();

    void on_tool_Btn_pass3_clicked();

    void on_tool_Btn_pass4_clicked();

    void on_tool_Btn_pass5_clicked();

    void on_tool_Btn_pass6_clicked();

    void on_tool_Btn_pass7_clicked();

    void on_tool_Btn_pass8_clicked();

    void on_tool_Btn_pass9_clicked();

    void on_tool_Btn_pass0_clicked();

    void on_tool_Btn_pass1_clicked();

    void on_toolButton_car_all_clicked();

    void on_toolButton_car_guding_clicked();

    void on_toolButton_car_gulin_clicked();

    void on_toolButton_car_gulinout_clicked();

    void on_toolBtn_tempcar1_clicked();

    void on_toolBtn_tempcar0_clicked();

    void on_toolButton_car_gulinall_clicked();
    void quit_carNumberIn();
    void quit_carNumberOut();

    void write_back_str(QString str);
    void updatePosition();
    void on_lineEdit_IN_CAR_textChanged(const QString &arg1);

    void on_pushButton_form_ok_clicked();
    void on_toolButton_form_y_clicked();
    void on_toolButton_form_n_clicked();
    void in_out_record();
signals:
    void send_cameraIn(QString);
    void send_cameraOut(QString);
    void send_icnum(QString);
    void send_msg(QString);
    void send_serIP_change();
};

#endif // MAINWINDOW_H
